﻿// <copyright file="EslToken.cs" company="Codeplex project Eco.Contrib"> 
// The MIT License (MIT) 
// </copyright> 
// <author>Peter Buchmann</author> 

namespace Eco.Contrib
{
    using System.Globalization;

    /// <summary>
    /// ESLTokenType enumeration
    /// </summary>
    public enum EslTokenType
    {
        /// <summary>
        /// Word enum
        /// </summary>
        Word,

        /// <summary>
        /// Operator enum
        /// </summary>
        Operator,

        /// <summary>
        /// Number enum
        /// </summary>
        Number,

        /// <summary>
        /// End enum
        /// </summary>
        End,

        /// <summary>
        /// StringContent enum
        /// </summary>
        StringContent,

        /// <summary>
        /// Comment enum
        /// </summary>
        Comment,

        /// <summary>
        /// Unknown enum
        /// </summary>
        Unknown
    }

    /// <summary>
    /// ESLToken: Token of ESL
    /// </summary>
    public class EslToken
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EslToken"/> class.
        /// </summary>
        /// <param name="tokenType">Type of the token.</param>
        /// <param name="tokenValue">The token value.</param>
        /// <param name="line">The line.</param>
        /// <param name="col">The col.</param>
        /// <param name="pos">The pos.</param>
        public EslToken(EslTokenType tokenType, string tokenValue, int line, int col, int pos)
        {
            this.TokenType = tokenType;
            this.TokenValue = tokenValue;
            this.Line = line;
            this.Col = col;
            this.Pos = pos;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EslToken"/> class.
        /// </summary>
        /// <param name="tokenType">Type of the token.</param>
        /// <param name="tokenValue">The token value.</param>
        public EslToken(EslTokenType tokenType, string tokenValue)
        {
            this.TokenType = tokenType;
            this.TokenValue = tokenValue;
            this.Line = -1;
            this.Col = -1;
            this.Pos = -1;
        }

        /// <summary>
        /// Gets or sets the type of the token.
        /// </summary>
        /// <value>
        /// The type of the token.
        /// </value>
        public EslTokenType TokenType { get; set; }

        /// <summary>
        /// Gets or sets the token value.
        /// </summary>
        /// <value>
        /// The token value.
        /// </value>
        public string TokenValue { get; set; }

        /// <summary>
        /// Gets or sets the line.
        /// </summary>
        /// <value>
        /// The line.
        /// </value>
        public int Line { get; set; }

        /// <summary>
        /// Gets or sets the col.
        /// </summary>
        /// <value>
        /// The col.
        /// </value>
        public int Col { get; set; }

        /// <summary>
        /// Gets or sets the pos.
        /// </summary>
        /// <value>
        /// The pos.
        /// </value>
        public int Pos { get; set; }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public new string ToString()
        {
            if ((this.Line == -1) && (this.Col == -1))
            {
                return this.TokenType.ToString() + " '" + this.TokenValue + "'";
            }
            else
            {
                return this.TokenType.ToString() + " '" + this.TokenValue + string.Format(CultureInfo.CurrentCulture, "' ({0},{1})", this.Line, this.Col);
            }
        }
    }
}
